﻿using System;
using RazorEngine;
using ThirdPartyLib.RazorEngineTemplatingDemo.Models;

namespace ThirdPartyLib.RazorEngineTemplatingDemo
{
    class Program
    {
        static void Main(string[] args)
        {
            /******************************************************************
            ** 
            ** Not only is Razor great for MVC, but it also makes for fantastic 
            ** templating language. I've not found anything better than Razor 
            ** for templating. Plus, those that use Razor have virtually 
            ** nothing new to learn. 
            **
            ** https://github.com/Antaris/RazorEngine
            **
            ******************************************************************/


            var model = new Person
            {
                FirstName = "Joe",
                LastName = "Somebody",
                Age = 32,
                Address = new Address
                {
                    Number = 1234,
                    Street = "Main St.",
                    City = "Louisville",
                    State = State.KY
                },
                PhoneNumbers = new[]
                {
                    "502-123-4567",
                    "502-987-6543"
                }
            };

            var template = @"
                My name is @Model.FirstName @Model.LastName and I am @Model.Age years old.
                I live at @Model.Address.Number @Model.Address.Street in @Model.Address.City, @Model.Address.State.
        
                I have had the following phone numbers:
                @foreach(var p in Model.PhoneNumbers) {
                    <text>@p</text>
                }
            ";

            //Here's where the magic happens
            //It only takes one line of code. 
            var result = Razor.Parse(template, model);

            Console.WriteLine(result);
            Console.ReadLine();

        }
    }
}
